<template>
  <edu-dialog
    width="75%"
    class="bombScreen systemDialog"
    @close="close"
    :isCustomTitle=true
    :autoHeight=false
    :visible.sync="showDialog">
    <span slot="title" v-for=" (titleItem, $index) in bombScreenList" :key="$index">
      <template v-if="msgIndex === $index">
        <img class="title-img" src="/static/images/icon/icon_title.png" /><span class="title-span">{{titleItem.title}}</span>
      </template>
    </span>

    <div class="info" v-for=" (msg, index) in bombScreenList" :key="index">
      <template v-if="msgIndex === index">
        <div class="info-date" v-if="msg.createTime">{{$t('workbench.releaseDate')}}{{msg.createTime | formatDate}}</div>
        <div class="info-content" v-html="msg.content"></div>
        <div class="info-attach">
            <div v-for="(attach,index) in msg.commonAttachmentList" :key="index">
                <div class="attach-item" v-if="attach.fileName" @click="handleDownloadfile(attach.fileLacation)">
                    <i class="el-icon-document"></i>
                    <span class="attach-name">{{attach.fileName}}</span>
                </div>
            </div>
        </div>
      </template>
    </div>

    <span slot="buttons">
      <span class="button-left float-left notPrompt">
        <el-checkbox v-model="notPrompt">{{$t('workbench.notPrompt')}}</el-checkbox>
      </span>
      <span class="float-right">
        <span class="pageSty">{{msgIndex + 1}} / <span> {{bombScreenList.length}} </span></span>
        <el-button v-if="msgIndex !== 0" type="primary" @click="pre">{{$t('workbench.previous')}}</el-button>
        <el-button v-if="(msgIndex + 1) !== bombScreenList.length" type="primary" @click="next">{{$t('workbench.next')}}</el-button>
      </span>
      <div class="clear-both"></div>
    </span>
  </edu-dialog>
</template>

<script>
import { getBombscreenList, setBombscreenNotPrompt } from "common/src/api/public/information"
import filters from "common/src/filters"
import { downloadfile } from "common/src/api/upload"

export default {
  name: 'Bombscreen',
  data() {
    return {
      notPrompt: false,
      showDialog: false,
      bombScreenList: [],
      queryParams: {
        pageNum_: 1,
        pageSize_: 20
      },
      msgIndex: 0
    }
  },
  created () {
    // this.getBombscreenList()
  },
  methods: {
    getBombscreenList() {
      getBombscreenList().then(res => {
        let data = res && res.data || [];
        this.bombScreenList = data;
        if (this.bombScreenList.length) {
          this.showDialog = true
        }
      })
    },
    // 下一条消息
    next() {
      if (this.msgIndex + 1 < this.bombScreenList.length) {
        this.msgIndex ++;
      }
    },
    // 上一条消息
    pre() {
      if (this.msgIndex > 0) {
        this.msgIndex --;
      }
    },
    // 处理下载文件
    handleDownloadfile(objectkey) {
      if (!objectkey) return;
      downloadfile(objectkey);
    },
    close () {
      let noTipsMsg = [];
      this.bombScreenList.forEach(item => {
        noTipsMsg.push(item.id);
      });
      console.log(this.notPrompt)
      if (this.notPrompt) {
        setBombscreenNotPrompt({
          noTipsMsg: noTipsMsg.join(',')
        })
      }
    }
  },
  filters: {
    formatDate(date) {
      return filters.formatDate(new Date(date).getTime(), "yyyy/MM/dd");
    }
  },
  watch: {
    notPrompt (val) {
      console.log(val)
    }
  }
}
</script>

<style lang="scss" scoped>
.pageSty {
  margin-right: 40px;
  background: #E9EDF0;
  border-radius: 12px;
  padding: 3px 5px;
}
.notPrompt .el-checkbox span.el-checkbox__label{
  color: #8896A7;
}
.bombScreen {
  height: 100%;
  overflow: hidden;
  .title {
    font-size: 18px;
    color: #2B3B4E;
    letter-spacing: 0;
    line-height: 24px;
    font-weight: bolder;
    margin: 0;
    img {
      width: 24px;
      height: 24px;
      vertical-align: middle;
    }
    span {
      vertical-align: middle;
    }
    .more-link {
      float: right;
      font-size: 14px;
      color: #3A7FE8;
      span {
        vertical-align: middle;
      }
      img {
        width: 12px;
        height: 12px;
        vertical-align: middle;
      }
    }
  }
  .announcement-list {
    margin-top: 4px;
    height: calc(100% - 28px);
    &.announcement-list-height{
      margin-top: 16px;
      height: calc(100% - 40px);
    }
    ul {
      height: 100%;
    }
    ul, li {
      list-style: none;
      margin: 0;
      padding: 0;
    }
    &::-webkit-scrollbar {/*滚动条整体样式*/
      width: 6px;
      height: 1px;
    }
    &::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
      border-radius: 3px;
      -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
      background: #D4D8DC;
    }
    &::-webkit-scrollbar-track {/*滚动条里面轨道*/
      -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
      border-radius: 10px;
      background: #fff;
    }
    .announcement-info {
      height: 36px;
      line-height: 36px;
      font-size: 14px;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      &.li-announcement-info {
        height: calc(100% / 7);
        line-height: 100%;
      }
      &:hover {
        color: #3A7FE8;
        cursor: pointer;
        .order-wrapper {
          color: #FFFFFF;
          background: #3A7FE8;
        }
        .date {
          color: #3A7FE8;
        }
      }
      &:first-child, &:nth-child(2), &:nth-child(3) {
        .order-wrapper {
          color: #FFFFFF;
          background: #3A7FE8;
        }
      }
      .order-wrapper {
        display: inline-block;
        width: 16px;
        height: 16px;
        line-height: 16px;
        font-size: 12px;
        text-align: center;
        border-radius: 50%;
        color: #2A3B4F;
        background: #E5E9EF;
        margin-right: 8px;
      }
      .topping {
        margin-right: 4px;
        width: 16px;
        height: 16px;
        vertical-align: middle;
      }
      .info-content {
        flex: 1;
        vertical-align: middle;
        padding-right: 50px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .date {
        color: #8896A7;
      }
    }
  }
  .title-img {
    width: 24px;
    height: 24px;
    vertical-align: middle;
  }
  .title-span {
    margin-left: 8px;
    font-size: 18px;
    color: #2B3B4E;
    vertical-align: middle;
  }
  .info {
    .info-content {
      margin-top: 15px;
      max-width: 100%;
    }
    .info-attach {
        padding: 10px 0;
        .attach-item {
            display: inline-block;
            padding: 3px 0;
            .attach-name {
                margin-left: 5px;
                cursor: pointer;
            }
            &:hover {
                .attach-name {
                    color: #409eff;
                }
            }
        }
    }
  }
}
</style>
<style lang="scss">
.notPrompt .el-checkbox span.el-checkbox__label{
  color: #8896A7;
}
</style>
